package mappers;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import model.Answer;
import dto.AnswerDTO;

public class AnswerMapper {

	@PersistenceContext
	EntityManager em;

	public AnswerDTO mapDOMtoDTO(Answer dom) {
		AnswerDTO dto = new AnswerDTO();

		dto.setId(dom.getId());
		dto.setCorrect(dom.isCorrect());
		dto.setText(dom.getText());

		return dto;

	}

	public Answer mapDTOtoDOM(AnswerDTO dto) {
		Answer dom = null;

		if (dto.getId() == 0) {
			dom = new Answer();
		} else {
			dom = em.find(Answer.class, dto.getId());
		}
		
		dom.setCorrect(dto.isCorrect());
		dom.setText(dto.getText());

		return dom;

	}

}
